/**
* @description: 849. 到最近的人的最大距离
* @author hewei
* @date 2022/9/5 14:20
* @version 1.0
*/

public class MaxDistToClosest {

    public int maxDistToClosest(int[] seats) {
        int ans = 1;
        int l = -1;
        for (int i = 0; i < seats.length; i++) {
            if (seats[i] == 1) {
                if (l == -1) ans = Math.max(ans, i);
                else ans = Math.max(ans, (i - l) / 2);
                l = i;
            }
        }
        ans = Math.max(ans, seats.length - 1 - l);
        return ans;
    }
}
